<div class="box box-solid">
    <div class="box-header with-border">
        <h3 class="box-title">IP查询</h3>
    </div>
    <div class="box-body">
        {!! $html !!}
    </div>
    <div class="box-footer">
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <div class="btn-group pull-left">
                <button type="reset" class="btn btn-warning pull-right">Reset</button>
            </div>
            <div id="submitBtn" class="btn-group pull-right">
                <button type="submit" class="btn btn-info pull-right">Submit</button>
            </div>
        </div>
    </div>
</div>
<script>
    $('#submitBtn').click(function () {
        ipSearchAction()
    })

    function ipSearchAction() {
        let t = $('form').serializeArray();
        let d = {}
        $.each(t, function () {
            d[this.name] = this.value;
        });
        $.ajax({
            url: "{{url('admin/ip_search_action')}}",
            data: d,
            dataType: 'json',
            type: 'post',
            success: function (res) {
                let ele = $('textarea')[0]
                let count = $('input[name=count]')[0]
                if (res.status === 1) {
                    $(ele).val(JSON.stringify(res.data.result))
                    $(count).val(res.data.count)
                }
                if (res.data.count <= 0) {
                    setTimeout(function () {
                        ipSearchAction()
                    }, 10000)
                }else{
                    ipLinkStatus(res.data.ip)
                    let i = setInterval(function () {
                        console.log(isQueryContinue)
                        if(!isQueryContinue){
                            clearInterval(i)
                        }
                        ipLinkStatusQuery(res.data.ip)
                    }, 5000)
                }
            }
        })
    }

    function ipLinkStatus(ip) {
        $.ajax({
            url: "{{url('admin/ip_link_status')}}",
            data: {ip: ip},
            dataType: 'json',
            type: 'get',
            success: function (res) {
                console.log(res)
            }
        })
    }
    let isQueryContinue = true
    function ipLinkStatusQuery(ip) {
        $.ajax({
            url: "{{url('admin/ip_link_status_query')}}",
            data: {ip: ip},
            dataType: 'json',
            type: 'get',
            success: function (res) {
                if(parseInt(res.continue) === 0){
                    isQueryContinue = false
                    let ele = $('textarea')[1]
                    $(ele).val(res.result)
                }
            }
        })
    }
</script>
